/**
 * @file longitudinal_control
 * @author yq
 * @brief 
 * @version 0.1
 * @date 24-3-18
 *
 * @copyright Copyright (c) 2024
 */
#ifndef CONTROLLER_LONGITUDINAL_CONTROL_H
#define CONTROLLER_LONGITUDINAL_CONTROL_H

struct PidConf {
    double kp;          // PID超参数kp
    double ki;          // PID超参数ki
    double kd;          // PID超参数kd
    double windup_guard; // 积分饱和保护
    double low_bound; // 输出边界值
    double up_bound; // 输出边界值
    double real_ratio;  // 真实值
    double target;      // 目标值
    double error;       // PID误差
    double pre_error;   // PID上次误差
    double derivative_error; // PID微分误差
    double integral_error;   // PID积分误差

    PidConf(double kp = 0.0, double ki = 0.0, double kd = 0.0, double target = 0.5, double windup_guard = 3.0,
            double low_bound = 0, double up_bound = 100);
    void SetKp(double p);
    void SetKi(double i);
    void SetKd(double d);
    void SetTarget(double target);
    void SetRealRatio(double ratio);
};

class Pid {
private:
    PidConf pidconf;

public:
    Pid(PidConf pidconf);
    double GetTarget() const;
    double GetRealRatio() const;
    void SetRealRatio(double real_ratio);
    void SetTarget(double target);
    double Output();
};

#endif //CONTROLLER_LONGITUDINAL_CONTROL_H
